<!DOCTYPE html>
<html lang='en'>
<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Document</title>
    <script type='text/javascript' src='js/vue.js'></script>
</head>
<body>
    <div id='app'>
        <h1>简单计算器</h1>
        数字A：<input type="text" v-model="a"><br>
        数字B：<input type="text" v-model="b"><br>
        <button @click="getSum">计算和</button>
        <button @click="getSum1">计算和,延迟2秒显示</button>
        <div v-text="sum"></div>
    </div>
    <script type='text/javascript'>
        var vm = new Vue({
            el: '#app',
            data: {
                a: '',
                b: '',
                sum: ''
            },
            methods: {
                getSum() {
                    this.sum = parseInt(this.a) + parseInt(this.b)
                },
                getSum1() {
                    //这里不能用普通函数，否则this指向window，有问题
                    setTimeout(() => {
                        this.sum = parseInt(this.a) + parseInt(this.b)
                    },2000)
                }
            }
        });
    </script>
</body>
</html>